package com.imooc.security.core.validate.code;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 4.10.2 创建短信验证码类
 * 
 * @author qilongfei
 *
 */
// 5.10.5 序列化以支持redis持久化存储
// public class ValidateCode {
public class ValidateCode implements Serializable{
	
	private static final long serialVersionUID = -8469071750306217985L;
	private String code;
	private LocalDateTime expireTime;

	/**
	 * 4.10.3 构造方法，过期时间点
	 * @param image
	 * @param code
	 * @param expireIn
	 */
	public ValidateCode(String code, int expireIn) {
		this.code = code;
		this.expireTime = LocalDateTime.now().plusSeconds(expireIn);
	}
	
	public ValidateCode(String code, LocalDateTime expireTime) {
		this.code = code;
		this.expireTime = expireTime;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public LocalDateTime getExpireTime() {
		return expireTime;
	}

	public void setExpireTime(LocalDateTime expireTime) {
		this.expireTime = expireTime;
	}
	
	public boolean isExpired(){
		return LocalDateTime.now().isAfter(expireTime);
	}
}
